# -*-  coding:utf-8 -*- 
# Author : lihongliang

"""
一：编写3个函数，每个函数执行的时间不一样
提示：可以使用time。sleep(2),让程序sleep 2S或者更多

二：编写装饰器，为每个函数加上统计运行时间的功能
提示： 在函数开始执行时间加上start= time。time（） 就可记录当前执行的时间戳，函数执行结束后在time.time()-start 就可以拿到执行所用时间

三：编写装饰器，为函数加上认证功能，即要去认证成功后才能执行函数

四：编写装饰器，为多个函数加上认证的功能（用户的账户密码来源文件），要求登录一次，后续函数无需输入用户名和密码
提示：从文件中读取字符串形式的字典，可以用  eval(''{"name":"egon","password":"123"}')转换成字典格式

def login(func):
    def inner():
        username = input("请输入用户名:").strip()
        password = input("请输入密码：").strip()

        with open("userinfo.txt",'r',encoding='utf-8') as f:
            userinfo = f.read().strip(',')
            userinfo = eval(userinfo)
            print(userinfo)
            if username in  userinfo['name'] and password in userinfo['password']:
                print("欢迎登录成功！")
            else:
                print("用户名或者密码错误！")

    return inner


def home():
    print("heme".center(50,"*"))
@login
def name():
    print("hello ")

home()
name()

"""

"""
# -*- coding:utf-8 -*-
# LC
username = input("please input your username:")         #输入用户名
#检查用户名是否被锁住
lock_read = open("lock_file.txt","r")
for lock in lock_read:
    lock_user = lock.strip()        #取出lock文件里面的用户信息
    if username == lock_user:
        print("You have been locked!")
        break
    else:
        continue
lock_read.close()                   #读取完毕

if username != lock_user:
    password = input("please input your password:")         #如果用户没有再lock文件中，则输入密码
    with  open("user_lis.txt") as user_info:            #打开用户账号文件
        for account in user_info:                               #查看输入的用户是否再账号文件内
            account_user = account.strip().split(",")[0]
            account_pass = account.strip().split(",")[1]
            if username == account_user:                        #如果输入的用户名在用户文件中存在
                if password == account_pass:
                    print("welcome to login")               #密码正确，则判断登录成功
                    break
                else:
                    print("wrong password!")                #否则密码错误，重新输入密码，即可用再输入两次
                    for count in range(0,2):
                        count = count + 1
                        password = input("please input your password:")
                        if password == account_pass:
                            print("welcome to login")          #如果再次输入的密码正确，则跳出
                            break
                        else:
                            print("wrong password")
                    if count == 2:                              #如果三次输错，则写入lock文件中，采用追加写入的方式
                        lock_write = open("lock_file.txt","a+")
                        lock_write.write("\n")
                        lock_write.write(username)
                        lock_write.close()
        if username!=account_user:                                     #如果账号文件内没有此账号，则提出没有此用户信息
            print("No this user")
 """

username = input("情输入用户名：")
lock_read = open("lock_file.txt","r")
for lock in lock_read:
    lock_user =lock.strip()
    if username == lock_user:
        print("You have been locked")
        break
    else:
        continue
lock_read.close()

count = 0
while True:
    if username != lock_user:
        password = input("请输入用户密码：")
        with open("user_lis.txt") as user_info:
            for account in user_info:
                account_user = account.strip().split(",")[0]
                account_pass = account.strip().split(",")[1]
                if username == account_user and password == account_pass:
                    print("欢迎进入系统！")
                    break
                else:
                    print("用户名或者密码错误！")
                    count +=1

















